//package com.kayangts.common;
//
//
//import com.kayang.nadapt.util.StringUtil;
//import com.netflix.hystrix.HystrixCommand;
//import com.netflix.hystrix.HystrixCommandGroupKey;
//import com.netflix.hystrix.HystrixCommandProperties;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.client.RestTemplate;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//public class TokenHystrixCommand extends HystrixCommand<String> {
//
//    private String token;
//    private RestTemplate restTemplate;
//    private HttpServletRequest request;
//    private HttpServletResponse response;
//
//    public TokenHystrixCommand( String token, RestTemplate restTemplate, HttpServletRequest request, HttpServletResponse response) {
//        super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("TokenInterceptor")).andCommandPropertiesDefaults(
//                HystrixCommandProperties.Setter().withExecutionIsolationThreadTimeoutInMilliseconds(10_000)
//        ));
//
//        this.token = token;
//        this.restTemplate = restTemplate;
//        this.request = request;
//        this.response = response;
//    }
//
//    @Override
//    protected String run() throws Exception{
//        // 业务逻辑
//        String jwsTokenSrcName= "JwsToken";
//        String jwsTokenCtxName= "";
//        String url = StringUtil.format("http://{0}/{1}checkToken", jwsTokenSrcName, jwsTokenCtxName);
//        HttpHeaders httpHeaders = new HttpHeaders();
//        httpHeaders.add("token", token);
//        HttpEntity httpEntity = new HttpEntity(httpHeaders);
//        ResponseEntity<HttpMsg> responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, HttpMsg.class);
//        if(responseEntity.getStatusCodeValue() != 200){
//            String errMsg = responseEntity.getBody().getMsg();
//            throw new CommonException(errMsg);
//        }
//        HttpMsg httpMsg = responseEntity.getBody();
//        Object jsonUc = httpMsg.getResult();
//
//        return jsonUc.toString();
//    }
//
//    @Override
//    protected String getFallback() {
//        Throwable throwable = getExecutionException();
//
//        // 降级逻辑
//
//        return "Fallback: " + token;
//    }
//
//}